home *** CD-ROM | disk | FTP | other *** search
Lisp/Scheme | 1985-04-27 | 2.8 KB | 91 lines | [TEXT/MACA] |
- ;+
- ; STEPLIB: A library of useful functions needed by the STEP 1.0
- ; debugging tool.
- ;-
-
- ;+
- ; autoload
- ; Load a large function when it's called for the first time. After loading
- ; the function then call it with whatever parameters were specified in the
- ; first time call.
- ;
- ; format
- ; (autoload name file)
- ; name - name of function to autoload.
- ; file - filename of file which contains function.
- ;-
- (defmacro autoload (name file)
- `(defun ,name (&rest rest) (load (etoa ',file)) (apply ,name rest) ))
-
- ;+
- ; case
- ; Select an alternative based on the value of a selector.
- ;
- ; format
- ; (case <selector> [(<key> [<action>]...)]... )
- ; selector - an expression which will be evaluated to determine which
- ; action to perform.
- ; key - a quoted sexpr. If key matches the value of selector,
- ; the <action>s corresponding to this key are evaluated.
- ; action - an sexpr which will be evaluated if its key matches the
- ; value of the selector.
- ; returns - the value of the last action in the chosen list of actions.
- ; If no key matches the selector's value and if one of the
- ; keys is 't', then the value of the last action in 't's
- ; actions. If no catchall 't' is present then returns nil.
- ;-
- (defun case (selector &rest options)
- (do* ((restl options (cdr restl)) (result nil))
- ((let ((label (caar restl)))
- (cond ((or (equal selector label)
- (eq t label) )
- (setq result (cdar restl)) )
- (t (null restl)) ) )
- (eval (rplacd '(progn) result)) ) ) )
-
-
- ;+
- ; etoa
- ; Convert expression to ascii string.
- ;
- ; format
- ; (etoa <expr>)
- ; <expr> - an expression whose value print string will be returned.
- ;-
- (defun etoa (symbol) (apply 'strcat (mapcar 'chr (explode symbol))))
-
- ;+
- ; short-princ
- ; Print an s-expression using princ, but don't print out the contents
- ; of nested lists. Instead print (...).
- ;
- ; format
- ; (short-princ <expr>)
- ; <expr> an expression whose value will be short-printed.
- ;-
- (defun short-princ (sexpr)
- (cond ((consp sexpr)
- (princ "(")
- (dolist (item sexpr)
- (if (consp item)
- (princ "(...)")
- (princ item) )
- (princ " ") )
- (princ ")") )
- (t (princ sexpr)) ) )
-
- ;+
- ; spaces
- ; Print out some spaces.
- ;
- ; format
- ; (spaces <num> [<sink>])
- ; <num> - number of spaces to print to the sink.
- ; <sink>- the output sink (defaults to standard output)
- ;-
- (defun spaces (n &optional sink)
- (cond ((null sink)(setq sink *standard-output*)))
- (dotimes (count n t)
- (write-char 32 sink) ) )
-
-